package org.gbif.biogarage.util;

import java.io.File;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


/**
 * Constant values used throughout the application.
 */
public class AppConfig {
	protected static final Log log = LogFactory.getLog(AppConfig.class);
	public static final String SESSION_USER = "user";
    private Configuration cfg;
    private File configFile;
    
    public AppConfig(String configFile) throws ConfigurationException{
    	cfg = new PropertiesConfiguration(configFile);
    }
    
    public String getBaseURL(){
    	String base = cfg.getString("app.baseUrl");
    	while (base.endsWith("/")){
    		base=base.substring(0, base.length()-1);
    	}
        return base;
    }
    public String getProperty(String property){
        return cfg.getString(property);
    }
    
	public static File getClasspathFile(String path){
		return new File(ClassLoader.getSystemResource(path).getFile());
	}
	public static String classpath2Filepath(String path){
		return new File(ClassLoader.getSystemResource(path).getFile()).getAbsolutePath();
	}

}
